package com.yan.stream;

import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

/**
 * @author taoge
 * @Date 2024/8/5 10:43
 * @Description
 */
public class StreamDemo1 {
    public static void main1(String[] args) throws IOException {
        String name = "Hellow Stream";
        FileOutputStream fos = new FileOutputStream("D:\\course\\02-javaSE进阶\\素材\\a.text");
        byte[] bytes = name.getBytes();
        for (byte aByte : bytes) {
            fos.write(aByte);
        }
        fos.close();
    }

    public static void main2(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("D:\\course\\02-javaSE进阶\\素材\\a.text");
        int len = -1;
        while((len = fis.read()) != -1){
            System.out.print(((char) len));
        }
    }

    public static void main3(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("D:\\course\\02-javaSE进阶\\素材\\053-环形链表.avi");
        FileOutputStream fos = new FileOutputStream("D:\\course\\02-javaSE进阶\\素材\\b\\053-环形链表.avi");
        int len = -1;
        while((len = fis.read()) != -1){
            fos.write(len);
        }
        fos.close();
        fis.close();
    }

    public static void main4(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("D:\\course\\02-javaSE进阶\\素材\\053-环形链表.avi");
        FileOutputStream fos = new FileOutputStream("D:\\course\\02-javaSE进阶\\素材\\b\\053-环形链表.avi");
        byte[] car = new byte[1024];
        int len = -1;
        while((len = fis.read(car)) != -1){
            fos.write(car , 0 , len);
        }
        fos.close();
        fis.close();
    }

    public static void main5(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("D:\\course\\02-javaSE进阶\\素材\\b.txt");
        FileOutputStream fos = new FileOutputStream("D:\\course\\02-javaSE进阶\\素材\\b\\b.txt");
        byte[] car = new byte[1024];
        int len = -1;
        while((len = fis.read(car)) != -1){
            fos.write(car , 0 , len);
        }
        fos.close();
        fis.close();
    }

    public static void main(String[] args) throws IOException {
        FileReader fr = new FileReader("D:\\course\\02-javaSE进阶\\素材\\c.java" , Charset.forName("GB2312"));
        FileWriter fw = new FileWriter("D:\\course\\02-javaSE进阶\\素材\\b\\c.java", Charset.forName("UTF-8"));
        int len = -1;
        while((len = fr.read()) != -1){
            fw.write(len);
        }

        fw.close();
        fr.close();
    }




}
